package com.leetcode.problems055;


/**
 * https://leetcode-cn.com/problems/jump-game/
 * @Date 2021/11/20 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution2 {


    public boolean canJump(int[] nums) {
        //最远可以到达的下标
        int maxPos = 0;
        for (int i = 0; i < nums.length; i++) {
            if(i > maxPos){
                continue;
            }
            maxPos = Math.max(maxPos,i + nums[i]);
            if(maxPos >= nums.length - 1){
                return true;
            }
        }
        return false;
    }



    public static void main(String[] args) {
        int nums[] = {3,2,1,0,4};
        System.out.println(new Solution2().canJump(nums));
    }
}
